/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年2月16日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

/**
 * @Type A20200216_fbnq
 * @Desc
 * @author 52489
 * @date 2020年2月16日
 * @Version V1.0
 */
public class A20200220_tiree {

    public void create(TireTreeNode node, String str) {
        char d[] = str.toCharArray();
        for (int i = 0; i < d.length; i++) {
            int loc = d[i] - 'a';
            if (node.childs[loc] == null) {
                node.childs[loc].data = d[i];
            }
            node = node.childs[loc];
        }
        node.isEnd = true;
    }

    public boolean find(TireTreeNode node, String str) {
        char d[] = str.toCharArray();
        for (int i = 0; i < d.length; i++) {
            int loc = d[i] - 'a';
            if (node.childs[loc] == null) {
                return false;
            } else {
                node = node.childs[loc];
            }
        }
        return node.isEnd;
    }

}

class TireTreeNode {
    final static int MAX_SIZE = 26;
    char data;
    boolean isEnd = false;
    TireTreeNode[] childs;

    /**
     * @param data
     * @param isEnd
     */
    public TireTreeNode(char data, boolean isEnd) {
        childs = new TireTreeNode[MAX_SIZE];
        isEnd = false;
    }

}